/*************************************************************************
	> File Name: sigqueue.c
	> Author: Angel Criss
	> Blog: blog.abbycin.tk 
	> Created Time: Sun 22 Jun 2014 07:32:12 PM CST
 ************************************************************************/

#define _POSIX_C_SOURCE 199309
#include<signal.h>
#include<unistd.h>
#include<stdio.h>
#include<errno.h>
#include<sys/types.h>

int main(int argc, char *argv[])
{

    if(argc<3)
    {
        printf("%s PID sig\n",argv[0]);
        _exit(0);
    }

    pid_t pid;
    int sig,i;
    union sigval value;

    printf("\nPID:\t%d\n",getpid());
    pid=atoi(argv[1]);
    sig=atoi(argv[2]);
    if(argc>3)
    {
        value.sival_int=atoi(argv[3]);
    }

    if(sigqueue(pid,sig,value)==-1)
        _exit(errno);
    if(argc>3)
    {
        for(i=0;i<atoi(argv[3]);i++)
            if(sigqueue(pid,sig,value)==-1)
            _exit(errno);
    }
}
